package org.windblog.core.servlet.comment;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.windblog.core.entity.Comment;
import org.windblog.core.CommentService;

@SuppressWarnings("serial")
public class SetCommentServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String action = request.getParameter("action");
		String commentKey = request.getParameter("comment");
		String curview = request.getParameter("curview");
		if (commentKey != null) {
			Comment comment = CommentService.getComment(commentKey);
			
			if (action != null&&comment!=null) {
				if (action.equals("approve")) {
					comment.approve();
				}else if(action.equals("unapprove"))
				{
					comment.unapprove();
				}else if(action.equals("spam"))
				{
					comment.spam();
				}
				CommentService.setComment(comment);
			}
		}

		if(curview==null||curview.trim().length()==0)
			response.sendRedirect("/admin/editComments.jsp");
		else
			response.sendRedirect("/admin/editComments.jsp?comment_status="+curview);
	}
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		doGet(request,response);
	}
}
